package com.hmall.search.config;

import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestClientBuilder;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class ElasticSearchConfig {

    //es服务器的地址
    private static final String url = "http://linux:9200";

    /**
     * RestHighLevelClient对象：操作es搜索引擎的核心对象
     *
     * @return
     * @Bean注解：将方法的返回值 RestHighLevelClient 放入Spring框架中管理
     */
    @Bean
    public RestHighLevelClient restHighLevelClient() {
        HttpHost httpHost = HttpHost.create(url);
        RestClientBuilder builder = RestClient.builder(httpHost);
        return new RestHighLevelClient(builder);
    }

}